/*
 * KCommand.java
 *
 * Created on 2007. �prilis 22., 16:07
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package lemmings;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 *
 * @author attila
 */
public class KCommand {
    private String commandstr; // a teljes parancssori bemenet
    private ArrayList<String> cmdargs; // a parnacs sz�tbontva
    private int db; // a param�terhossz
    
    /** Creates a new instance of KCommand */
    public KCommand() {
    }
    
    public KCommand(String cmd) {
        StringTokenizer valaszt = new StringTokenizer(cmd, " ", false);
        cmdargs = new ArrayList<String>();
        db = valaszt.countTokens();
        int i;
        
        for (i=0; i<db; i++) {
            cmdargs.add(i, valaszt.nextToken());
        }
    }
    
    public String getCommand() throws NullPointerException
    {
        if (cmdargs==null)
            throw new NullPointerException();
        else
            try{
    		return cmdargs.get(0);
            } catch(IndexOutOfBoundsException e){
    		System.out.println("Nincs ilyen parameter!");
    		return null;
            }
    }
    
    public String getArgs(int n) throws NullPointerException
    {
        if (cmdargs==null)
            throw new NullPointerException();
        else
            try{
    		return cmdargs.get(n);
            } catch(IndexOutOfBoundsException e){
    		System.out.println("Nincs ilyen parameter!");
    		return null;
            }
    }
    
    public void printArgs() {
        int i;
        
        if (cmdargs!=null) {
            System.out.println("@ + "+cmdargs.get(0));
            for (i=1; i<db; i++) System.out.println("@  - " + cmdargs.get(i));
        }
        
        return;
    }
    
    public int argNum() {
        if (cmdargs!=null) return db; else return 0;
    }
}
